getShopCar();
/*获取购物车信息*/
function getShopCar() {
    var arr=[];
    $.get("http://localhost:8080/src/data/shopcar.json",{},function (res) {
//               console.log(res);
        var num=0;
        var bol=true;
        for(var i=0;i<res.length;i++){
            if(res[i].isChoose=="false"){
                bol=false;
            }
        }
        $("#checkAll").prop("checked",bol);
        getGoods(num,res);
    });
    /*获取商品信息*/
    function getGoods(num,res){
        $.get("http://localhost:8080/showGoods",{
            id:res[num].id,
            url:"shangpinlist1.json"
        },function (data) {
//                    console.log(data);
            data.buyCount=res[num].count;
            data.isChoose=res[num].isChoose;
            arr.push(data);
            num++;
            if(num<res.length){
                getGoods(num,res);
            }
            if(arr.length==res.length){
                var obj={};
                obj.arr=arr;
                var sum=0;
                $("#list").html(baidu.template("tmp",obj));
                for(var i=0;i<res.length;i++){
                    var bol=res[i].isChoose=="true"?true:false;
                    $(".check").eq(i).prop("checked",bol);
                    if(bol){
                        sum+=arr[i].buyCount*arr[i]["product_price"];
                    }
                }
                $("#checkAll").next().text(sum);
            }
        });
    }
}

/*改变数量*/
function changeCount(id,type) {
    $.post("http://localhost:8080/changeCount",{
        id:id,
        type:type
    },function (res) {
//                console.log(res);
        getShopCar();
    });
}
/*删除单个商品*/
function delOneGoods(id) {
    $.post("http://localhost:8080/delOneGoods",{
        id:id
    },function (res) {
        console.log(res);
        getShopCar();
    });
}
/*全选*/
$("#checkAll").click(function () {
    $.post("http://localhost:8080/checkAll",{
        isChoose:$("#checkAll").prop("checked")
    },function (res) {
        console.log(res);
        getShopCar();
    });
});
/*单选*/
function oneChoose(ck,id) {
    var bol=ck=="true"?false:true;
    $.get("http://localhost:8080/oneChoose",{
        id:id,
        isChoose:bol
    },function (res){
       console.log(res);
       getShopCar();
    });
}
